package minimumSwitchingTimes;

import java.util.HashMap;
import java.util.Map;

//public class Solution {
//    public int minimumSwitchingTimes(int[][] source, int[][] target) {
//        // 贪心 尽量多移动无人机的位置
//        // 有多少无人机的颜色是已经相同的
////        Map<Integer,Integer> map = new HashMap<>();
////        for (int i = 0; i < source.length; i++) {
////            for (int j = 0; j < source[i].length; j++) {
////                map.put(source[i][j],map.getOrDefault(source[i][j],0)+1);
////            }
////        }
////        int ans = 0;
////        for (int i = 0; i < target.length; i++) {
////            for (int j = 0; j < target[i].length; j++) {
////                int t = map.getOrDefault(target[i][j],0);
////                if(t<=0) {
////                    ans++;
////                }else {
////                    map.put(target[i][j],t-1);
////                }
////            }
////        }
////        return ans;
//    }
//}
class Solution {
    public int minimumSwitchingTimes(int[][] source, int[][] target) {
        int n=source.length,m=source[0].length,sum=0;
        int[] p=new int[10005];
        for(int i=0;i<n*m;i++){
            p[source[i/m][i%m]]++;
            p[target[i/m][i%m]]--;
        }
        for(int i=0;i<10005;i++){
            if(p[i]>0) sum+=p[i];
        }
        return sum;
    }
}
